<admintpl file="header" />
<style>
.col-md-6{width:45%;}
#const,#version_id{width:300px;}
</style>
<script  src="__PUBLIC__/js/My97DatePicker/WdatePicker.js"></script>
<script type="text/javascript" src="__PUBLIC__/ckeditor/ckeditor.js"></script>
<script type="text/javascript" src="__PUBLIC__/teamwork/bootstrap-select.js"></script>
<link rel="stylesheet" type="text/css" href="__PUBLIC__/teamwork/bootstrap-select.css">
<link href="__PUBLIC__/teamwork/bootstrap.min.css" rel="stylesheet">
<script src="__PUBLIC__/teamwork/bootstrap.min.js"></script>
<script type="text/javascript">
//时间选择
function selecttime(flag){
    if(flag==1){
        var endTime = $("#countTimeend").val();
        if(endTime != ""){
            WdatePicker({dateFmt:'yyyy-MM-dd HH:mm',maxDate:endTime});
        }else{
            WdatePicker({dateFmt:'yyyy-MM-dd HH:mm'});
        }
    }else{
        var startTime = $("#countTimestart").val();
        if(startTime != ""){
            WdatePicker({dateFmt:'yyyy-MM-dd HH:mm',minDate:startTime});
        }else{
            WdatePicker({dateFmt:'yyyy-MM-dd HH:mm'});
        }    
    }
}
 
</script>
</head>
<body>
    <div class="wrap">
        <ul class="nav nav-tabs">
            <li><a href="{:U('TeamWorks/index')}">{:L('ADMIN_TEAMWORK_INDEX')}</a></li>
            <li><a href="{:U('TeamWorks/add')}">{:L('ADMIN_TEAMWORK_ADD')}</a></li>
			<li><a href="{:U('TeamWorks/add_type')}">{:L('ADMIN_TEAMWORK_ADD_TYPE')}</a></li>
			<li class="active"><a href="{:U('TeamWorks/edit',array('id'=>$result['id']))}">{:L('ADMIN_TEAMWORK_EDIT')}</a></li>
        </ul>
        <form method="post" class="form-horizontal js-ajax-form" action="{:U('TeamWorks/edit_post')}"  enctype="multipart/form-data">
           <input type="hidden" name="id" value="{$result['id']}"/>

            <div class="form-group">
                <label class="col-md-2 control-label"><span style="color:red;"> * </span>{:L('TEAMWORK')}</label>
                <div class="col-md-6">
                    <input type="text" class="form-control" name="title" value="{$result.title}" placeholder="请输入您要安排的工作任务名称">
                </div>
            </div>
			<div class="form-group">
                <label class="col-md-2 control-label">{:L('TYPES')}</label>
                <div class="col-md-6">
                    <select name="types" class="form-control" id="const">
                        <option value="1" <if condition="$type['type_id'] eq 1">selected="selected"</if> >分类</option>
                        <option value="2" <if condition="$type['type_id'] eq 2">selected="selected"</if> >项目</option>
                    </select>
                </div>
            </div>
			<div class="form-group">
                <label class="col-md-2 control-label">{:L('TYPES')}</label>
                <div class="col-md-6">
                    <select name="type_id" class="form-control" id="version_id">
                        <foreach name="types" item="vo">
                            <option value="{$vo.id}" <if condition="$result['type_id'] eq $vo['id']">selected="selected"</if>>{$vo.name}</option>
                        </foreach>
                    </select>
                </div>
            </div>
			<div class="form-group">
                <label class="col-md-2 control-label"><span style="color:red;"> * </span>{:L('WORK_TIME')}</label>
                <div class="col-md-6">
                    <input type="text" name="start_time" id="countTimestart" onfocus="selecttime(1)" value='{$result.start_time|date="Y-m-d H:i",###}' size="17" class="date" readonly> - <input type="text" name="end_time" id="countTimeend" onfocus="selecttime(2)" value='{$result.end_time|date="Y-m-d H:i",###}' size="17"  class="date" readonly> 
                </div>
            </div>
			<div class="form-group">
                <label class="col-md-2 control-label"><span style="color:red;"> * </span>{:L('RESP')}</label>
                <div class="col-md-6">
					<select name="resp_id" class="selectpicker bla bla bli form-control">
						<foreach name="departs" item="vo">
						<optgroup label="{$vo.department_name}">
							<foreach name="vo.users" item="user">
								<option value="{$user.id}" <if condition="$result['resp_id'] eq $user['id']">selected="selected"</if>>{$user.real_name}</option>
							</foreach>
						</optgroup>
						</foreach>
                    </select>
                </div>
            </div>
            
            <div class="form-group">
                <label class="col-md-2 control-label">{:L('PART')}</label>
                <div class="col-md-6">
                    
					<select id="id_select" class="selectpicker bla bla bli form-control" multiple data-live-search="true" name="part_ids[]">
						<foreach name="departs" item="vo">
						<optgroup label="{$vo.department_name}">
							<foreach name="vo.users" item="user">
								<option value="{$user.id}" <php>$arr = explode(',',trim($result['part_ids'],','));if(in_array($user['id'],$arr)){echo 'selected="selected"';}</php>>{$user.real_name}</option>
							</foreach>
						</optgroup>
						</foreach>
				  </select>
                </div>
            </div>
			<div class="form-group">
                <label class="col-md-2 control-label">{:L('APPROVE')}</label>
                <div class="col-md-6">
					<select name="approve_id" class="selectpicker bla bla bli form-control">
                        <foreach name="departs" item="vo">
						<optgroup label="{$vo.department_name}">
							<foreach name="vo.users" item="user">
								<option value="{$user.id}" <if condition="$result['approve_id'] eq $user['id']">selected="selected"</if>>{$user.real_name}</option>
							</foreach>
						</optgroup>
						</foreach>
                    </select>
                </div>
            </div>
			<div class="form-group">
                <label class="col-md-2 control-label">{:L('DESCRIPTION')}</label>
                <div class="col-md-6">
					<textarea cols="70" rows="13"  name="description" id="content">{$result.description}</textarea>
                </div>
            </div>
            
            

            <div class="form-actions col-md-10 col-md-offset-2">
                <button type="submit" class="btn btn-primary ">{:L('EDIT')}</button>
                <a class="btn btn-default" href="javascript:history.back(-1);">{:L('BACK')}</a>
            </div>
        </form>
    </div>
	<script src="__PUBLIC__/js/common.js"></script>
	
    <script>
	$(document).ready(function(e) {
			
			//阶段与版本联动
			$("#const").on("change", function(){
				getSelectVal();
			});
			function getSelectVal(){
				$.getJSON("{:U('TeamWorks/get_types')}",{type_id:$("#const").val()},function(json){ 
					var version_id = $("#version_id"); 
					$("option",version_id).remove(); //清空原有的选项 
					$.each(json,function(index,array){ 
						var option = "<option value='"+array['id']+"'>"+array['name']+"</option>"; 
						version_id.append(option); 
					}); 
				});
			}
			$('.selectpicker').selectpicker({
                'selectedText': 'cat'
            });
			CKEDITOR.replace('content',{
				toolbar :
				[
					['Styles', 'Format'],
					['Bold', 'Italic', '-', 'NumberedList', 'BulletedList', '-', 'Link', '-', 'Underline']
				],
				uiColor : '#9AB8F3',
				height:'200'
			});
			
	});
	</script>
</body>
</html>